// import { Message } from 'element-ui'
import $qs from "qs";
import Cookies from "js-cookie";
import Vue from "vue";
let vueObj = new Vue();
import request from "@/utils/request";
import router from "../../router";
let m = () => {
  vueObj
    .$confirm(`已提交导出请求,系统正在进行导出,是否查看导出结果？`, "提示", {
      confirmButtonText: "去看看",
      cancelButtonText: "不了",
      type: "success"
    })
    .then(() => {
      router.push({ path: "/basicdata/downloadCenter" });
    })
    .catch(() => {
      vueObj.$message({
        type: "success",
        message: "提交成功"
      });
    });
};
export default {
  bind(el, binding, vnode) {
    const { path, isBase = true, query, redirect } = Object.assign(
      {},
      binding.value
    );
    // console.log(binding.value, 'binding.value')
    // console.log(redirect, 'redirectredirect')
    const root = isBase
      ? Cookies.get("BASE_API") || `${location.protocol}//${location.hostname}/`
      : `${location.protocol}//${location.hostname}/`;
    // console.log(location.protocol, location.hostname, 'locayion')
    // console.log(Cookies.get('BASE_API'), 'base-api')
    const open = redirect && redirect.length > 0 ? redirect : `${root}${path}`;
    // console.log(`${open}${$qs.stringify(query)}`, `${open}`)
    // console.log(root, open, 'rootopen')
    el.addEventListener(
      "click",
      $el => {
        const $query = el.dataset.query;
        if (query && $query) {
          Object.assign(query, JSON.parse($query));
        }
        console.log(query,'222')
       if (query == undefined) {
               location.href = query ? `${open}${$qs.stringify(query)}` : `${open}`
        } else if(query.liveplay===1 || query.liveplay===0 || query.type=='toutiaoapp' || query.type=='aliapp' || query.type=='icon'){//判断微信小程序打包下载是否是直播版或标准版，以及头条或支付宝走或设置中心=》其他设置的下载图标按钮是要走之前的逻辑
          location.href = query ? `${open}${$qs.stringify(query)}` : `${open}`
        }else {
          vueObj
            .$prompt("请填入表单备注", "备注", {
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              type: "warning"
            })
            .then((value) => {
              query.remark = value.value
  
              let dataRe = request({
                url: "/" + path.split("&")[0],
                method: "post",
                data: $qs.stringify(query)
              });
              dataRe.then(res => {
                if (res.data.data == true) {
                  m();
                } else {
                  vueObj.$message({
                    type: "info",
                    message: "操作失败"
                  });
                }
              });
            })
            .catch(() => {
              vueObj.$message({
                type: "info",
                message: "已取消"
              });
            });
        }

        //console.log('______href_______', query ? `${open}${$qs.stringify(query)}` : `${open}`)
        // location.href = query ? `${open}${$qs.stringify(query)}` : `${open}`
      },
      false
    );
  }
};
